package com.zhentao.controller;

import com.zhentao.model.common.buiness.dto.BuProductUpAndDownDto;
import com.zhentao.model.common.buiness.pojo.Product;
import com.zhentao.model.common.buiness.vo.BuProductVO;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.service.BuProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/bu/product")
@Api(tags = "product",description = "商家端的接口")
public class BuProductController {
    @Autowired
    private BuProductService buProductService;
    /**
     * 商家端:商品添加
     * @param product
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("商家端：商品添加添加接口")
    public ResponseResult productSave(@RequestBody Product product){
        return buProductService.productSave(product);
    }

    /**
     * 商家端:商品查询
     * @param vo
     * @return
     */
    @PostMapping("/findAll")
    @ApiOperation("商家端：商品查询")
    public ResponseResult productFindAll(@RequestBody BuProductVO vo){
        return buProductService.productFindAll(vo);
    }


    /**
     * 商家端：处理从前端传过来的图片
     * @param file
     * @return
     */
    @PostMapping("/file")
    @ApiOperation("商家端：文件上传")

    private String file(MultipartFile file){
       return buProductService.fiie(file);
    }


    /**
     * 根据商品id查询商品
     * @param id
     * @return
     */
    @PostMapping("/findByProductId")
    @ApiOperation("商家端：根据id查询")
    public ResponseResult findByProductId(@RequestParam("id") Integer id){
        return buProductService.findByProductId(id);
    }



    /**
     * 商家端：商品上下架
     * @param dto
     * @return
     */
    @PostMapping("/upAndDown")
    @ApiOperation("商家端：商品上下架")
    public ResponseResult upAndDown(@RequestBody BuProductUpAndDownDto dto){
        return buProductService.upAndDown(dto);
    }


    /**
     * 商家端：用户信息
     * @param id
     * @return
     */
    @GetMapping("/userinfo/{id}")
    public ResponseResult userInfo(@PathVariable("id")Integer id){
        return buProductService.userInfo(id);
    }
}
